<?php

namespace App\Http\Controllers\Api\Dynamic;

class Test
{
    public function test ()
    {

        // 获取当前登录用户的好友列表
        $friendIds = Friendship::where('user_id', $currentUserId)->pluck('friend_id');

// 获取互相关注的用户列表
        $mutualFriendIds = Friendship::whereIn('friend_id', $friendIds)
            ->where('user_id', $currentUserId)
            ->pluck('friend_id');

// 查询动态并过滤权限
        $query = Dynamic::where('privacy_level', 'public')
            ->orWhere(function ($query) use ($currentUserId, $friendIds) {
                $query->where('privacy_level', 'friends')
                    ->whereIn('user_id', $friendIds);
            })
            ->orWhere(function ($query) use ($currentUserId) {
                $query->where('privacy_level', 'custom')
                    ->where('custom_user_id', $currentUserId);
            })
            ->orWhere(function ($query) use ($currentUserId, $mutualFriendIds) {
                $query->where('privacy_level', 'mutual_friends')
                    ->whereIn('user_id', $mutualFriendIds);
            })
            ->orderBy('created_at', 'desc');
    }
}
